package com.maixy.rabbitmqdemo.delay;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName DelayRabbitConfig
 * @Description 延迟队列配置类
 * @Date 2021/3/23 20:52
 * @Author maixy
 */
@Configuration
public class DelayRabbitConfig {

    @Bean
    public CustomExchange delayExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange("delay_exchange_1", "x-delayed-message",true, false,args);
    }

    @Bean
    public Queue queue() {
        return new Queue("delay_queue_1", true);
    }

    @Bean
    public Binding binding(Queue queue, CustomExchange delayExchange) {
        return BindingBuilder.bind(queue).to(delayExchange).with("delay_queue_1").noargs();
    }
}
